home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / idlelib / Percolator.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  106 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. from WidgetRedirector import WidgetRedirector
  5. from Delegator import Delegator
  6.  
  7. class Percolator:
  8.     
  9.     def __init__(self, text):
  10.         self.text = text
  11.         self.redir = WidgetRedirector(text)
  12.         self.top = self.bottom = Delegator(text)
  13.         self.bottom.insert = self.redir.register('insert', self.insert)
  14.         self.bottom.delete = self.redir.register('delete', self.delete)
  15.         self.filters = []
  16.  
  17.     
  18.     def close(self):
  19.         while self.top is not self.bottom:
  20.             self.removefilter(self.top)
  21.         self.top = None
  22.         self.bottom.setdelegate(None)
  23.         self.bottom = None
  24.         self.redir.close()
  25.         self.redir = None
  26.         self.text = None
  27.  
  28.     
  29.     def insert(self, index, chars, tags = None):
  30.         self.top.insert(index, chars, tags)
  31.  
  32.     
  33.     def delete(self, index1, index2 = None):
  34.         self.top.delete(index1, index2)
  35.  
  36.     
  37.     def insertfilter(self, filter):
  38.         if not isinstance(filter, Delegator):
  39.             raise AssertionError
  40.         if not filter.delegate is None:
  41.             raise AssertionError
  42.         filter.setdelegate(self.top)
  43.         self.top = filter
  44.  
  45.     
  46.     def removefilter(self, filter):
  47.         if not isinstance(filter, Delegator):
  48.             raise AssertionError
  49.         if not filter.delegate is not None:
  50.             raise AssertionError
  51.         f = self.top
  52.         if f is filter:
  53.             self.top = filter.delegate
  54.             filter.setdelegate(None)
  55.         else:
  56.             while f.delegate is not filter:
  57.                 if not f is not self.bottom:
  58.                     raise AssertionError
  59.                 f.resetcache()
  60.                 f = f.delegate
  61.             f.setdelegate(filter.delegate)
  62.             filter.setdelegate(None)
  63.  
  64.  
  65.  
  66. def main():
  67.     
  68.     class Tracer(Delegator):
  69.         
  70.         def __init__(self, name):
  71.             self.name = name
  72.             Delegator.__init__(self, None)
  73.  
  74.         
  75.         def insert(self, *args):
  76.             print self.name, ': insert', args
  77.             self.delegate.insert(*args)
  78.  
  79.         
  80.         def delete(self, *args):
  81.             print self.name, ': delete', args
  82.             self.delegate.delete(*args)
  83.  
  84.  
  85.     root = Tk()
  86.     root.wm_protocol('WM_DELETE_WINDOW', root.quit)
  87.     text = Text()
  88.     text.pack()
  89.     text.focus_set()
  90.     p = Percolator(text)
  91.     t1 = Tracer('t1')
  92.     t2 = Tracer('t2')
  93.     p.insertfilter(t1)
  94.     p.insertfilter(t2)
  95.     root.mainloop()
  96.     p.removefilter(t2)
  97.     root.mainloop()
  98.     p.insertfilter(t2)
  99.     p.removefilter(t1)
  100.     root.mainloop()
  101.  
  102. if __name__ == '__main__':
  103.     from Tkinter import *
  104.     main()
  105.  
  106.